import View from "ol/View";
import TileLayer from "ol/layer/Tile"
import TileArcGISRest from 'ol/source/TileArcGISRest'
import OSM from "ol/source/OSM"
import XYZ from 'ol/source/XYZ'

/**
 * 获取图层列表
 * @param {*} maptype 0表示部署的离线瓦片地图，1表示OSM,2表示使用Arcgis在线午夜蓝地图服务
 * @returns 
 */
let mapLayerArr = (maptype = 2) => {
    var maplayer = null;
    switch (maptype) {
        case 0:
            maplayer = new TileLayer({
                source: new XYZ({
                    url: 'http://127.0.0.1:7080/streetmap/shenzhen/{z}/{x}/{y}.jpg'
                })
            })
            break;
        case 1:
            maplayer = new TileLayer({
                source: new OSM()
            })
            break;
        case 2:
            maplayer = new TileLayer({
                source: new TileArcGISRest({
                    url: 'https://map.geoq.cn/ArcGIS/rest/services/ChinaOnlineCommunity/MapServer'
                })
            })
            break;
    }
    return [maplayer];
}

/**
 * 获取视图控制。控制地图中心、缩放级别和投影
 * @returns 
 */
let view = () => {
    return new View({
        projection: "EPSG:4326",    //使用这个坐标系
        center: [114.064839, 22.548857],  ////中心点经度和纬度，深圳
        zoom: 15 //地图缩放级别
    })
}

var mapconfig = {
    view,
    mapLayerArr
};

export default mapconfig
